//
//  TOActivityDetail.m
//  X-Tribe
//
//  Created by Miss.Ou on 16/4/2.
//  Copyright © 2016年 Miss.Ou. All rights reserved.
//

#import "TOActivityDetail.h"

@interface TOActivityDetail ()

@property(nonatomic,strong)UISegmentedControl *segmentC;
@property(nonatomic,strong)UIView *infoV;
@property(nonatomic,strong)UIView *picV;
@property(nonatomic,strong)UIView *personV;

@end

@implementation TOActivityDetail

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
        self.backgroundColor = [UIColor whiteColor];
    }
    
    return self;
}

-(void)createSubviews{
    
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"活动详情",@"参与人员",@"活动照片", nil];
    self.segmentC = [[UISegmentedControl alloc]initWithItems:array];
    _segmentC.backgroundColor = [UIColor yellowColor];
    self.segmentC.frame = CGRectMake(0, 0, SCREEN_WIDTH, 50);
    [self addSubview:_segmentC];
    //设置按钮选中颜色
    _segmentC.tintColor = [UIColor brownColor];
    //点击事件
    [_segmentC addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
    
    self.infoV = [[UIView alloc] init];
    self.infoV.backgroundColor = [UIColor redColor];
    [self addSubview:self.infoV];
    [self.infoV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
        
    }];
    self.picV = [[UIView alloc] init];
    self.picV.backgroundColor = [UIColor yellowColor];
    [self addSubview:self.picV];
    [self.picV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
        
    }];
    self.personV = [[UIView alloc] init];
    self.personV.backgroundColor = [UIColor blueColor];
    [self addSubview:self.personV];
    [self.personV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
        
    }];
    

    [self bringSubviewToFront:self.segmentC];



}

-(void)segmentedAction:(UISegmentedControl *)segmentC
{
    //打印点击按钮下标
    NSLog(@" === %ld",segmentC.selectedSegmentIndex);
    if (segmentC.selectedSegmentIndex == 0) {
        self.infoV.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
        [self bringSubviewToFront:self.infoV];
        
        
    }
    else if(segmentC.selectedSegmentIndex == 1){
        self.personV.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];

        [self bringSubviewToFront:self.personV];
        
        
    }else{
        self.picV.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
        
        [self bringSubviewToFront:self.picV];
    
    }
    [self bringSubviewToFront:segmentC];
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
